import { createSlice, PayloadAction } from '@reduxjs/toolkit'

export type userInfoType = {
  name?: string
  username: string
  avatar?: string
  job?: string
  organization?: string
  location?: string
  email?: string
  permissions?: Record<string, string[]>
  id: string
  roles: Record<string, any>
}
const INIT_STATE: userInfoType = {
  id: '',
  username: '',
  roles: {}
}

const userReducer = createSlice({
  name: 'user',
  initialState: INIT_STATE,
  reducers: {
    setUserInfo: (_draft: userInfoType, action: PayloadAction<userInfoType>) => {
      return action.payload
    }
  }
})
export const { setUserInfo } = userReducer.actions
export default userReducer.reducer
